package com.geek.pokermanager.controller;

import javax.servlet.http.HttpServletRequest;

import org.apache.commons.lang.StringUtils;
import org.apache.oro.text.regex.StringSubstitution;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import com.geek.pokermanager.base.BaseController;
import com.geek.pokermanager.model.PokerStore;
import com.geek.pokermanager.service.PokerStoreService;
import com.geek.pokermanager.util.UUIDTool;

/**
 * 牌库管理
 * @author Administrator
 *
 */

@Controller
@RequestMapping(value="pokerStore")
public class PokerStoreController extends BaseController{
	@Autowired
	private PokerStoreService storeService;
	
	
	@RequestMapping(value="managerPage")
	public String managerPage(Model model){
		model.addAttribute("Context",basePath());
		model.addAttribute("ContextPath",request.getContextPath());
		return "storeManager";
	}
	
	@ResponseBody
	@RequestMapping(value="addStore", produces = "text/html;charset=utf8")
	public String addStore(HttpServletRequest request,@RequestBody PokerStore store){
		if(store!=null){
			store.setPokerStoreId(UUIDTool.getUUID());
			storeService.addStore(store);
			returnResult.setMsg("添加成功！");
		}
		else
			returnResult.setMsg("添加失败！");
		return resultVal();
	}
	

	@SuppressWarnings("unchecked")
	@ResponseBody
	@RequestMapping(value="getStore", produces = "text/html;charset=utf8")
	public String getStore(){
		returnResult.setData(storeService.getStore(""));
		return resultVal();
	}
	
	@ResponseBody
	@RequestMapping(value="delStore", produces = "text/html;charset=utf8")
	public String delStore(String storeId){
		if(StringUtils.isNotBlank(storeId)){
			storeService.deleteStore(storeId);
			returnResult.setMsg("删除成功");
		}
		return resultVal();
	}
	
}
